<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <title>${title}</title>
 	<link rel="stylesheet" href="${basePath}/static/bootstrap/css/bootstrap.css"/>
    <link href="${basePath}/static/css/basic.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/login.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/list.css" rel="stylesheet" type="text/css">
 	<script  type="text/javascript" src="${basePath}/static/js/jquery.min.js"></script>
	<script  type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${basePath}/static/page/jqPaginator/jqPaginator.js"></script>
	<script  type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
	<link href="${basePath}/static/layer/layer_style.css" rel="stylesheet" type="text/css">
    
	<style type="text/css">
		    div,ul,li{margin:0;padding:0;}
            ul{line-style:none;}

            .select{position:relative;width:100px;min-width:134px;height:36px;border:1px solid #eee;cursor:pointer;}
            .select:after{content:"";position:absolute;top:50%;right:10px;margin-top:-2px;border-top:5px solid #666;border-right:5px solid transparent;border-left:5px solid transparent;}
            .select .select_text{padding:0 20px 0 10px;height:36px;line-height:36px;}
            .select_ul{display:none;position:absolute;top:34px;left:-1px;width:100px;min-width:134px;border:1px solid #D4D4D4;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background:#fff;}
            .select_ul li{line-height:36px;text-indent:10px;}
            .select_ul li:hover{color:#fff;background:#6AA7EA;}
            .select_ul li.cur{color:#fff;background:#195DA3;}
            .input_box3{height:28px;width:300px;}
	</style>
    
</head>
<body>
<!--头部-->
	<%@include file="/WEB-INF/templates/common/header.jsp"%>
	<!------导航条-->
	<%@include file="/WEB-INF/templates/common/navigation.jsp"%>
<!--内容部分-->
<div class="list_main lay_out" class="clearfix">
    <div class="list_DH">
         <%@include file="/WEB-INF/templates/common/qualityNav.jsp"%>
    </div>
    <div class="list_NR">
        <div class="loc">
            <h3 style="margin:0 0;width:auto;">质控审核</h3>
        </div>
        <div class="list_con_table">
            <div class="search_table">
                <ul class="clearfix"style="margin-bottom:0;">
                <input class="input_box" type="hidden"   name='' id="mqcId" value="" />
                <input class="input_box" type="hidden"   name='' id='firstGuid' value='${firstGuid}' />
                 <input class="input_box" type="hidden"   name='' id='operator' value='${qualityMapList[0].operator}' />
                <input class="input_box" type="hidden"   name='' id='preThirdProMsg' value='' />
                    <li class="Label_1">身份证：&nbsp;</li>
                    <li class="Label_2">
                    ${hospitalNote.idNumber}
                    <!--  <input class="input_box" type="text" disabled="disabled"  name='' id='idCard' value='${hospitalNote.idNumber}' />-->
                    </li>
                    <li class="Label_1">识别码：&nbsp;</li>
                    <li class="Label_2">
                    ${hospitalNote.mrId}
                    <!--  <input class="input_box" type="text"  disabled="disabled" name='' id='mrId' value='${hospitalNote.mrId}' />-->
                    </li>
                    <li class="Label_1">姓名：&nbsp;</li>
                    <li class="Label_2">
                    ${hospitalNote.name}
                    <!--  <input class="input_box" type="text"  name='' id='name' value='${hospitalNote.name}' />-->
                    </li>
                    <li class="Label_1" style="height:114px;line-height:114px;">质控项目：&nbsp;</li>
                    <li class="Label_4" style="width:52.98%;height:114px;padding-left:2px;">
                        <select class="input_box input_box3" onchange="getSecondProject()" name="" id="firstPro">
                            <option value="">-----  选择评价项目  -----</option>
                            <c:forEach var="firstStandard" items="${firstStands}">
                        		<option value="${firstStandard.id}">${firstStandard.project}</option>
                       		</c:forEach>
                        </select>
                        <br/>
                        <select class="input_box input_box3" onchange="thirdProject()" name="" id="secondPro">
                            <option value="">-----  选择二级评价项目 -----</option>
                           
                        </select>
                        <br/>
                        <select class="input_box input_box3" onchange="getProjectMsg()"  name="" id="thirdPro">
                            <option value="">----- 选择三级评价项目 -----</option>
                        </select>
                    </li>
                    <li class="Label_1" style="height:114px;line-height:114px;">扣分：&nbsp;</li>
                    <li class="Label_2" style="height:114px;line-height:114px;"><input type="text" class="input_box" name='' id='qcDockPoints' value='${medControlDesc.qcDockPoints}'/></li>
                    
                    <li class="Label_1" style="height:78px;line-height:78px;">质控内容：&nbsp;</li>
                    <li class="Label_4" style="width:86%;height:78px;padding:2px;">
                      <textarea id="medControlDesc" style="word-break:break-all; width:100%;height:60px;margin-top:9px;border: #e3e5e4 solid 1px">${medQualityControl.medControlDesc}</textarea>
                    </li>
                    <li class="Label_5">
                        <div class="right" style="text-align:right" id="opeBtn">
                            <!--  <a class="btn"id="Add" onclick="updateQua()">修改</a> -->
							 <a id="Add" onclick="addQuality()">新增</a>
							 <a style="width:auto;"onclick="skan()">查看患者数据</a>
                         	
                        </div>
                    </li>
                </ul>
            </div>
			   <table class="Search_tableList" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="tdLabel_4">姓名</td>
                    <td class="tdLabel_4">识别码</td>
                    <td class="tdLabel_4">出院科室</td>
                    <td class="tdLabel_4">评价项目</td>
                    <td class="tdLabel_4">扣分</td>
                     <td class="tdLabel_4">质控描述</td>
                    <td class="tdLabel_4">质控人</td>
                    <td class="tdLabel_4">操作</td>
                </tr>  
                <tbody id="tbody"></tbody>
             	<c:forEach items="${qualityMapList}" var="qualityMap">
				<tr>
                    <td class="tdLabel_5">${qualityMap.name}</td>
                    <td class="tdLabel_5">${qualityMap.mrId}</td>
                    <td class="tdLabel_5">${qualityMap.outOfficeName}</td>
                    <td class="tdLabel_5">${qualityMap.project}</td>
                    <td class="tdLabel_5">${qualityMap.qcPoints}</td>
                    <td class="tdLabel_5">${qualityMap.qualityDes}</td>
                    <td class="tdLabel_5">${qualityMap.qualityName}</td>
                    <td class="tdLabel_5">
                            <a class="int" mqcId="${qualityMap.medQuaFunId}"  mqId="${qualityMap.mqId}" onclick="deleteQua(this)">删除</a>
	                    	<a class='int' mqcId="${qualityMap.mqId}"  qualityDesc="${qualityMap.qualityDes}" thirdproj="${qualityMap.project}" qcDockPoint="${qualityMap.score}"  firstProId="${qualityMap.firstProId}" secondProId="${qualityMap.secondProId}" thirdProId="${qualityMap.thirdProId}" mrId="${qualityMap.mrId}" name="${qualityMap.name}"   onclick='update(this)'>修改</a>
	                </td>  		
                    <%-- <c:if test="${qualityMap.status==1}">
	                   
	                    	<a class="int" mqcId="${qualityMap.medQuaFunId}"  mqId="${qualityMap.mqId}" onclick="deleteQua(this)">删除</a>
	                    	<a class='int' mqcId="${qualityMap.mqId}"  qualityDesc="${qualityMap.qualityDes}" thirdproj="${qualityMap.project}" qcDockPoint="${qualityMap.score}"  firstProId="${qualityMap.firstProId}" secondProId="${qualityMap.secondProId}" thirdProId="${qualityMap.thirdProId}" mrId="${qualityMap.mrId}" name="${qualityMap.name}"   onclick='update(this)'>修改</a>
	                   		<a class="int" mqcId="${qualityMap.medQuaFunId}"   onclick="updateCheck(this)">审核</a> 
	                   
                    </c:if>--%>
                    
                    
                  <%--   <c:if test="${qualityMap.status==2}">
	                    <td class="tdLabel_5">
	                    	已审核
	                    </td>
                    </c:if> 
                    <c:if test="${qualityMap.status==3}">
	                    <td class="tdLabel_5">
	                    	已删除
	                    </td>
                    </c:if>--%>
                </tr>  
             	</c:forEach>
            </table> 
        </div>
    
    </div>
</div>
<!------页脚部分--------->
<%@include file="/WEB-INF/templates/common/footer.jsp"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery.select.js"></script>
<!--JS部分-->
<script>
	$(function(){
		$('select.select').select();		
	});

    function getSecondProject(){
    	var parentId=$("#firstPro").val();
    	$.ajax({
    		type:"post",
    		async:false,
    		data:{parentId:parentId},
    		url:"${basePath}/quality/getQualityProjectList",
    		success:function(data){
    			if(data!=null){
    				$("#secondPro").html("");
    				var html=" <option value=''>-----  选择二级评价项目 -----</option>";
    				for(var i in data){
    					var pro=data[i];
    					html+="<option value='"+pro.id+"'>"+pro.project+"</option>"
    				}
    				$("#secondPro").html(html);
    			}else{
    				$("#secondPro").html("");
    			}
    		}
    	})
    }
    
    
    function thirdProject(){
    	var parentId=$("#secondPro").val();
    	$.ajax({
    		type:"post",
    		async:false,
    		data:{parentId:parentId},
    		url:"${basePath}/quality/getQualityProjectList",
    		success:function(data){
    			if(data!=null){
    				$("#thirdPro").html("");
    				var html=" <option value=''>-----  选择三级评价项目 -----</option>";
    				for(var i in data){
    					var pro=data[i];
    					html+="<option value='"+pro.id+"'>"+pro.project+"</option>"
    				}
    				$("#thirdPro").html(html);
    			}else{
    				$("#thirdPro").html("");
    			}
    		}
    	})
    	
    	
    }
    
    
    function getProjectMsg(){
    	var id=$("#thirdPro").val();
    	$.ajax({
    		type:"post",
    		data:{id:id},
    		url:"${basePath}/quality/getPointsStandardById",
    		success:function(data){
    			if(data!=null){
    				var score=data.score;
    				var point=score==null?0:score
    				var total=$("#qcPoints").val();
    				
    				
    				$("#qcDockPoints").val(point);
    				$("#qcPoints").val(parseInt(total)-parseInt(point));
    			}
    		}
    	})
    	
    }
    
    //数据病案查看
    function skan(){
    	var guid=$("#firstGuid").val();
    	window.open('${corePath}/medical_record/searchHomePageIndexForm?visitGuid='+guid);
    	
    }
    
    //添加病案质控
    function updateQuality(){
    	var folderName=$("#folderName").val();
    	var medQualityLevel=$("#medQualityLevel").val();
    	var medControlDesc=$("#medControlDesc").val();
    	var qcPoints=$("#qcPoints").val();
    	var qcDockPoints=$("#qcDockPoints").val();
    	var medRecordLabel= $("#thirdPro").find("option:selected").text();
    	var mqcId=$("#mqcId").val();
    	$.ajax({
    		type:"post",
    		data:{id:mqcId,folderName:folderName,medQualityLevel:medQualityLevel,
    			medControlDesc:medControlDesc,qcPoints:qcPoints,qcDockPoints:qcDockPoints,medRecordLabel:medRecordLabel 			
    		},
    		url:"${basePath}/quality/updateMedQualityCont",
    		success:function(data){
    			window.location.href="${basePath}/quality/operateQua?firstGuid="+folderName;
    		}
    	})
     
    }
    
    
	
	 function page(currentPage,totalCounts){
	        var pageSize = 20;
	        var visiblePages = 5;
	        var totalPages = Math.ceil(totalCounts/pageSize);
	        $('#page_plus').jqPaginator({

	            totalCounts: totalCounts,
	            pageSize:pageSize,
	            visiblePages: visiblePages,
	            currentPage: currentPage,

	            first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
	            prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
	            next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
	            last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
	            page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
	            onPageChange: function (num,type) {
	            	
	            	 if(type !='init'){
	                 
	            		 queryQua(num-1,pageSize);
	                 }
	            	
	                $("#totalPage").html(totalCounts);
	                $("#currentPage").html(num+"/"+totalPages);
	            }
	        });

	    }
	
	
	 
	 //添加病案质控
	    function addQuality(){
	    	var qcDockPoints=0;
	    	var firstGuid=$("#firstGuid").val();
	    	var controlName=$("#operator").val();
	    	var medControlDesc=$("#medControlDesc").val();
	    	qcDockPoints=$("#qcDockPoints").val();
	    	var firstProId=$("#firstPro").val();
	    	var secondProId=$("#secondPro").val();
	    	var thirdProId=$("#thirdPro").val();
	    	if(!thirdProId){
	    		layer.alert("请选择评价项目!",{icon:7});
	    		return;
	    	}
	    	if(!qcDockPoints){
	    		layer.alert("扣分项不能为空!",{icon:7});
	    		return;
	    	}
	    	$.ajax({
	    		
	    		type:"post",
	    		data:{firstGuid:firstGuid,qcDockPoints:qcDockPoints,medControlDesc:medControlDesc,
	    			firstProId:firstProId,secondProId:secondProId,thirdProId:thirdProId
	    		},
	    		url:"${basePath}/quality/addMedQualityCont",
	    		success:function(data){
	    			window.location.href="${basePath}/quality/updateMedQua?firstGuid="+firstGuid;
	    		}
	    	})
	     
	    }
	 
	 //添加病案质控
/*     function addQuality(){
    	var qcDockPoints=0;
    	var uniqueKey=$("#firstGuid").val();
    	var operator=$("#operator").val();
    	var medControlDesc=$("#medControlDesc").val();
    	var qcPoints=$("#qcPoints").val();
    	qcDockPoints=$("#qcDockPoints").val();
    	var medRecordLabel= $("#thirdPro").find("option:selected").text();
    	var firstProId=$("#firstPro").val();
    	var secondProId=$("#secondPro").val();
    	var thirdProId=$("#thirdPro").val();
    	
    	if(!thirdProId){
    		layer.alert("请选择评价项目!",{icon:0});
    		return;
    	}
    	if(!qcDockPoints){
    		layer.alert("扣分项不能为空!",{icon:0});
    		return;
    	}
    	
/*     alert(uniqueKey+"--"+operator+"--"+medQualityLevel+"--"+medControlDesc+"--"+qcPoints+"--"+qcDockPoints+"--"+firstProId+"--"+secondProId+"--"+thirdProId+"--"+medRecordLabel);
    return;
    	 */
    
    
/*     	$.ajax({
    		
    		type:"post",
    		data:{folderName:uniqueKey,controlName:operator,medQualityLevel:medQualityLevel,
    			medControlDesc:medControlDesc,qcPoints:qcPoints,qcDockPoints:qcDockPoints,medRecordLabel:medRecordLabel,
    			firstProId:firstProId,secondProId:secondProId,thirdProId:thirdProId
    			
    		},
    		url:"${basePath}/quality/addMedQualityCont",
    		success:function(data){
    			window.location.href="${basePath}/quality/updateMedQua?folderName="+uniqueKey;
    		}
    	})
     
    } */ 
    
	 
	 
	 function update(obj){
		 var $this=$(obj);
		 var mqcId=$this.attr("mqcId");
		 var firstGuid=$("#firstGuid").val();
		 var firstProId=$this.attr("firstProId");
		 var secondProId=$this.attr("secondProId");
		 var thirdProId=$this.attr("thirdProId");
		 var qcDockPoint=$this.attr("qcDockPoint");
		 var medDesc=$this.attr("qualityDesc");
		 $("#medControlDesc").html(medDesc);
		 $("#qcDockPoints").val(qcDockPoint);
		 $("#mqcId").val(mqcId);
		 $("#preThirdProMsg").val($this.attr("thirdproj"));
		 var firstSelect = 0;
		 
		 $("#opeBtn").html("").html("<a  id='Add' onclick='updateQua()''>修改</a>");

		 if(firstProId!=null && firstProId!='') {
			 $("#firstPro").find("option").each(function() {
					if($(this).attr("value") == firstProId) {
						firstSelect = 1;
						
						$(this).prop("selected", true);
						
						getSecondProject();
					   }
				});
		 }
		 
		 if(secondProId!=null && secondProId!='' && firstSelect==1) {
			 
			 $("#secondPro").find("option").each(function() {
			
					if($(this).attr("value") == secondProId) {
						$(this).prop("selected", true);
						thirdProject();
						
						$("#thirdPro").find("option").each(function(){
							if($(this).attr("value")==thirdProId){
								$(this).prop("selected", true);
							}
						});
					 }
			});
		 
		 }
	 }
	 
	 
	 function updateQua(){
			var firstGuid=$("#firstGuid").val();
			var mqId=$("#mqcId").val();
			var medControlDesc=$("#medControlDesc").val();
			var qcDockPoints=$("#qcDockPoints").val();
			var firstProId=$("#firstPro").val();
	    	var secondProId=$("#secondPro").val();
	    	var thirdProId=$("#thirdPro").val();
	    	var medRecordLabel= $("#thirdPro").find("option:selected").text();
	    	var name=$("#name").val();
	    	var mrId=$("#mrId").val();
	    	var preThirdProMsg= $("#preThirdProMsg").val();
			if(!thirdProId){
				layer.alert("请选择评分项目!",{icon:0});
				return;
			}
	    	
	    	if(!qcDockPoints){
				layer.alert("扣分项不能为空!",{icon:0});
				return;
			}
		
	    	//alert(firstGuid+"--"+mqId+"--"+medControlDesc+"--"+qcDockPoints+"=="+firstProId+"--"+secondProId+"--"+thirdProId);
	    	
			$.ajax({
				type:"post",
				data:{id:mqId,qcDockPoints:qcDockPoints,medControlDesc:medControlDesc,firstProId:firstProId,secondProId:secondProId,thirdProId:thirdProId,firstGuid:firstGuid},
				url:"${basePath}/quality/updateQua",
				success:function(data){
					if(data=="success"){
						//layer.alert("质控信息修改成功",{icon:1});
						window.location.href="${basePath}/quality/updateMedQua?firstGuid="+firstGuid;
					}
				}
			})
		 }
	 
	 
	 function deleteQua(obj){
		 
	
		 var $this=$(obj);
		 var mqcId=$this.attr("mqcid");
		 var mqId = $this.attr("mqId");
		 var firstGuid=$("#firstGuid").val();
		 

		 $.ajax({
			 type:"post",
			 data:{mqcId:mqcId,mqId:mqId},
			 url:"${basePath}/quality/deleteQuality",
			 success:function(data){
				 if(data.success){
		    			$(obj).parents("tr").fadeOut("slow",function(){
							$(this).remove();
						});
	    				
	    			}
			 }
		 })
	 }
	 
	 function updateCheck(obj){
		 var mqcId=$(obj).attr("mqcId");
		 var status=2;
		 var firstGuid=$("#firstGuid").val();
		 $.ajax({
			 type:"post",
			 data:{mqcId:mqcId,status:status},
			 url:"${basePath}/quality/checkQua",
			 success:function(data){
				 if(data=='success'){
					 window.location.href="${basePath}/quality/updateMedQua?firstGuid="+firstGuid;
				 }else{
			
				 }
			 }
		 })
	 }
    
</script>
</body>
</html>